package com.huas.controller;

import cn.hutool.core.lang.tree.Tree;
import com.huas.common.Result;
import com.huas.dto.RoleMenuListDTO;
import com.huas.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/menuManagement")
@Slf4j
public class MenuController {
    @Resource
    private MenuService menuService;

    /**
     * 获取权限列表
     */
    @GetMapping
    @PreAuthorize("hasAuthority('menuManagement:select')")
    public Result<List<Tree<Integer>>> selectMenuList(){
        log.info("获取权限列表树");
        List<Tree<Integer>> list = menuService.selectMenuList();
        return Result.success(list);
    }
    /**
     * 修改角色权限
     */
    @PutMapping
    @PreAuthorize("hasAuthority('menuManagement:update')")
    public Result update(@RequestBody RoleMenuListDTO roleMenuListDTO){
        log.info("修改角色权限数据为：{}",roleMenuListDTO);
        String jwt = menuService.update(roleMenuListDTO);
        return Result.success(jwt);
    }
}
